<%@ page import="com.iweb.entity.User" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setCharacterEncoding("utf-8");
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    List<User> users = new ArrayList<>();
    //验证用户名的合法性
    users.add(new User("admin","123456"));
    users.add(new User("tom","aaabbb"));
    users.add(new User("jerry","123abc"));
    boolean isFound = false;

    for (User user:users) {
        if(user.getPassword().equals(password)&&user.getUsername().equals(username)){
            isFound = true;
            break;
        }
    }
    RequestDispatcher dispatcher =null;
    if(isFound){
        request.getAttribute("welcome.jsp");
        dispatcher.forward(request,response);
    }else {
        request.setAttribute("msg","用户名或者密码有误");
        dispatcher = request.getRequestDispatcher("login.jsp");
    }
    dispatcher.forward(request,response);


%>

